package com.ldf.jrtsp.pool;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * jrtsp线程池
 *
 * @author lidaofu
 * @since 2024/6/20
 **/
public class JRtspThreadPool {

    /**
     * jrtsp线程池
     */
    private final static ThreadPoolExecutor J2RTSP_THREAD_POOL = new ThreadPoolExecutor(
            8, 16, 60, TimeUnit.SECONDS
            , new LinkedBlockingDeque<>(256), new ThreadFactory() {
        private final AtomicInteger threadNumber = new AtomicInteger(1);

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r,"JRTSP-" + threadNumber.getAndIncrement());
        }
    });

    /**
     * 执行
     *
     * @param runnable
     */
    public static void execute(Runnable runnable) {
        J2RTSP_THREAD_POOL.execute(runnable);
    }

    /**
     * 停止
     */
    public static void shutdown() {
        J2RTSP_THREAD_POOL.shutdown();
    }
}
